//
//  CollectViewController.m
//  Qyer
//
//  Created by 赵宇 on 15/9/22.
//  Copyright (c) 2015年 赵宇. All rights reserved.
//

#import "CollectViewController.h"
#import "BaseHeader.h"
@interface CollectViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation CollectViewController

-(void)viewWillAppear:(BOOL)animated
{
    self.inforArr = [[NSMutableArray alloc]init];
    
    self.inforArr = [[DataBase shareDataBase]selectALL];
    
    if (_myCollection == nil) {
        UICollectionViewFlowLayout *myFlow = [[UICollectionViewFlowLayout alloc]init];
        myFlow.itemSize = CGSizeMake(SCREEN_WIDTH/7*3.1, SCREEN_WIDTH/7*2.1);
        [myFlow setSectionInset:UIEdgeInsetsMake(SCREEN_WIDTH/35, SCREEN_WIDTH/25, SCREEN_WIDTH/35, SCREEN_WIDTH/25)];
        _myCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-112) collectionViewLayout:myFlow];
        _myCollection.backgroundColor = [UIColor whiteColor];
        [_myCollection setDelegate:self];
        [_myCollection setDataSource:self];
        [_myCollection registerClass:[MyCollectCollectionViewCell class] forCellWithReuseIdentifier:@"myCollectCell"];
        [self.view addSubview:_myCollection];
    }
    [_myCollection reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.inforArr = [[NSMutableArray alloc]init];
    
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUpNavigation];

}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _inforArr.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    MyCollectCollectionViewCell *myCollectCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCollectCell" forIndexPath:indexPath];
    MyCollectModel *mod =[[MyCollectModel alloc]init];
    mod = [_inforArr objectAtIndex:indexPath.row];
    [myCollectCell setValueWithModel:mod];
    
    return myCollectCell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    AllCountViewController *city = [[AllCountViewController alloc]init];
    MyCollectModel *mod = [_inforArr objectAtIndex:indexPath.row];
    city.urlStr = mod.cid;
    
    [self.navigationController pushViewController:city animated:YES];
}
-(void)setUpNavigation
{
    UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    navView.backgroundColor = [UIColor whiteColor];
    UILabel *titLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH, 30)];
    titLab.text = @"我的足迹";
    titLab.font = [UIFont systemFontOfSize:17.];
    titLab.textAlignment = YES;
    titLab.textColor = [UIColor whiteColor];
    [navView addSubview:titLab];
    
    UIButton *backBut = [UIButton buttonWithType:UIButtonTypeCustom];
    backBut.frame = CGRectMake(10, 30, 30, 30);
    [backBut setImage:[UIImage imageNamed:@"iconfont-31fanhui1"] forState:UIControlStateNormal];
    [backBut addTarget:self action:@selector(goBackBefore) forControlEvents:UIControlEventTouchUpInside];
    [navView addSubview:backBut];
    navView.backgroundColor = [UIColor colorWithRed:34./255 green:169./ 255 blue:118./255 alpha:1];
    
    [self.view addSubview:navView];
}
-(void)goBackBefore
{
    // 让代理人去执行方法
//    [self.delegate sendMessage:_inforArr.count];
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
